<template>
	<view>
	<u-navbar title="详情页面" bgColor="#32B25D" :border="false"
	safeAreaInsetTop
	fixed
	placeholder
	titleStyle="font-size: 30rpx;color:#ffffff;font-weight: bold;"
	leftIconColor="#ffffff">
				<view class="u-flex" slot="left">
					<u-icon name="arrow-left" size="24" color="#ffffff" @click="back"></u-icon>
					<u-line direction="column" :hairline="false" length="26" margin="0 18px" ></u-line>
					<u-icon name="home" size="24" color="#ffffff" @click="backindex"></u-icon>
				</view>
	
	</u-navbar>
	
<u-swiper @change="e => current = e.current"
	:list="info.imgs"
	keyName="file_url"
	:autoplay="true"
	@click="preview"
	radius="0" height="220"
	:showTitle="true"
	v-if="info.imgs.length>0">
</u-swiper>
<div class="u-p-t-20 u-p-l-20">
	<u--form labelPosition="left" labelWidth="40">
	<u-form-item label="贡献照片" :borderBottom="false">
			<view class="u-flex u-flex-between" style="width: 100%;">
			  <view class="u-flex-2">
					<u-upload 
						:fileList="fileList1"
						@afterRead="afterRead"
						maxCount="1"
						@delete="deletePic"
						multiple
						name="1"
						width="50"
						height="50">
					</u-upload>
			  </view>
			  <view class="u-flex-2"><u-button type="primary" size="large" @tap="upimg" style="height: 50px;width: 50px;">上传</u-button></view>
			  <view class="u-flex-8">
				  <view class="u-p-l-20"></view>
			  </view>
			</view>
		</u-form-item>
	</u--form>
</div>
<u-gap height="6" bg-color="#f3f4f6" ></u-gap>
		<!--image style="width: 100%;" mode="widthFix" :src="info.cover" @click="preview(info.cover)" v-if="info.cover!=null"></image-->
		<view class="u-padding-20">
			<view class="b-b u-p-b-20 u-font-lg u-font-weight-bold">
			 <span class="u-error-dark">{{info.name}}</span>
			 <span v-if="info.aliastags!=null">,</span><span class="u-warning-dark" v-if="info.aliastags!=null">{{info.aliastags}}</span>
			</view>
			<view class="b-b u-p-t-20 u-p-b-20" v-if="info.classification!=''">【分类】{{info.classification}}</view>
			
			<view  v-for="(se, key) in info.section" :key="key">
				<view class="u-p-t-20 bittitle">【{{se.sectionname}}】</view>
				<view class="b-b u-p-t-20 u-p-b-20 bigtxt"><u-parse :content="se.content"></u-parse></view>
				<view  v-if="se.sectiontypeid==4||se.sectiontypeid==5">
					<view class="u-p-t-20 u-p-b-20" v-if="se.resembled_recipe.length>0">
						【相似度较高的药方】
						<view  v-for="(resemb, key) in se.resembled_recipe" :key="key">
						<span class="a-link u-primary-dark" @click="$Router.push({path: '/pages/componentsA/durg/archiveinfo', query: {aid: resemb.relationaid,sid:resemb.sid}})">
							{{resemb.name}}
						</span>
						</view>
					</view>
				</view>
			</view>
			<view class="u-p-t-20 u-p-b-20" v-if="info.physicalrelation_ids.length>0">
				【相关连结】
				<view v-for="(phyids, key) in info.physicalrelation_ids" :key="key">
				<span class="a-link u-primary-dark" @click="$Router.push({path: '/pages/componentsA/durg/archiveinfo', query: {aid: phyids.relationaid}})">
					{{phyids.relationcate}}
				</span>
				</view>
			</view>
			<view class="u-p-t-20 u-p-b-20" v-if="info.physicalrelation_other.length>0">
				【其他参考】
				<view  v-for="(phyother, key) in info.physicalrelation_other" :key="key">
				<span class="a-link u-primary-dark" @click="$Router.push({path: '/pages/componentsA/durg/archiveinfo', query: {aid: phyother.aid}})">
					{{phyother.name}}
				</span>
				</view>
			</view>
		</view>
		<u-gap height="70"></u-gap>
	</view>
</template>


<script>

import {mapState,mapMutations} from 'vuex';
import base from "@/config/baseUrl";
export default {

	data(){
		return {
			aid:'',
			info:{
				classification:'',
				physicalrelation_other:[],
				physicalrelation_ids:[],
				imgs:''
			},
			prewimg:[],
			content:'',
			fileuploadaction: base.baseUrl + "index/File/add_dcd",
			fileList1: [],
			list_img1:[],
		};
	},
	computed: {
	  ...mapState(['user']),
	},
  onLoad(options) {
	let query = JSON.parse(decodeURIComponent(options.query));
	console.log(query)
    this.getInfo(query.aid);
  },

methods:{
	back(){
		uni.navigateBack(1);
	},
	upimg(){
		if (this.fileList1.length==0){
			this.$tools.msg("请选择图片后即可上传");return;
		}
		this.fileList1=[]
		this.$tools.msg("感谢您的支持，上传的图片将在审核后显示。");
	},
		backindex(){
			//this.$tools.routerTo("/pages/componentsC/my/my",{},'');
			// uni.reLaunch({
			// 	url: '/pages/index/my'
			// })
			let pages = getCurrentPages(); 
			//函数用于获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面
			console.log('pages',pages.length)
			var num=pages.length
			//当前页面栈总数
			var backnum=0
			//需要返回的页数
			for(var i =0;i<num;i++){
				console.log('pagesroute...',pages[i].route)
				//循环找到指定页面路由所在的页数
				if(pages[i].route=='/'){
				//'pages/mypage/mypage'替换成A页面的路由地址
					backnum=num-i-1
					//计算返回的层数，总数-指定页面页数-1
				}
				console.log('backnum...',backnum)
			}
			if (backnum==0){
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}else{
				uni.navigateBack({
					delta:backnum
					//返回的页面数，如果 delta 大于现有页面数，则返回到首页。
				})
			}
		},
	
	getInfo(aid){
        return new Promise((resolve, reject) => {
                this.$api('dcd.archiveinfo', {
				aid:aid
			}).then(res => {
				console.log(res)
					if (res.code==200){
						this.info=res.data
					}
                }).catch((e)=>{
                resolve(false);
            });
        })
		
	},
	navigate(tags){
		console.log('==',tags)
	},
    preview(current){
	console.log('pre',current)
	 //let prewimg=this.item.cover.map(item =>(info.cover))
	 this.prewimg.push(this.info.imgs[current].file_url_big)
	 uni.previewImage({
	        urls: this.prewimg,
	        current: current
	    });
    },
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
				this[`list_img${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			// 新增图片
			async afterRead(event) {

				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].thumb,event.name)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
				
			},
			uploadFilePromise(url,index) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.fileuploadaction, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							table: 'info',
							aid:this.info.aid
						},
						header: {
							'MemberToken': this.user.tokenInfo,
							'Bid':this.user.bid
							},
						success: (res) => {
							let upfile=JSON.parse(res.data);
							setTimeout(() => {
								if (upfile.code==200){
									this[`list_img${index}`].push(upfile.data)
								}else{
									this.$tools.msg(upfile.msg);
									this[`fileList${index}`]=[];
									return;
								}
								resolve(res.data.data)
							}, 10)
						}
					});
				})
			},
	
	
}
	
};
</script>
<style lang="scss" scoped>
	.bittitle{
		font-size: 16px;font-weight: bold;line-height: 110%;
	}
	.bigtxt{
		font-size: 19px;
		line-height: 160%;
	}

.a-link{
	line-height: 200%;padding-left: 20px;
}
</style>
